package cn.edu.zju.gis.disasterBE.sever.dao;

import cn.edu.zju.gis.disasterBE.sever.Utils.MybatisUtils;
import cn.edu.zju.gis.disasterBE.sever.entity.imageQuery;
import cn.edu.zju.gis.disasterBE.sever.mapper.imageMapper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class imageDownDao {
    public static void write(imageQuery iQ) {
        SqlSession session = MybatisUtils.getSqlSession();
        imageMapper im = session.getMapper(imageMapper.class);

        System.out.print(iQ);

        im.addImage(iQ);
        session.close();
    }

    public static void downloaded(String id) {
        SqlSession session = MybatisUtils.getSqlSession();
        imageMapper im = session.getMapper(imageMapper.class);

        im.downloaded(id);
        session.close();
    }

    public static List<imageQuery> selectAll(){
        SqlSession session = MybatisUtils.getSqlSession();
        imageMapper dm = session.getMapper(imageMapper.class);
        List<imageQuery> res = dm.selectAll();
        session.close();
        return res;
    }

    public static String  midToFilename(String id){
        SqlSession session = MybatisUtils.getSqlSession();
        imageMapper im = session.getMapper(imageMapper.class);
        String filename = im.selectFileName(id);
        session.close();
        return filename;
    }
}
